package com.lzq.leetcode.hoot100;

import java.util.Arrays;

public class s189 {

    public void rotate(int[] nums, int k) {
        int len = nums.length;
        k = k % len;
        reverse(nums, 0, len);
        reverse(nums, 0, k);
        reverse(nums, k, len);
    }

    private void reverse(int[] nums, int l, int r) {
        int len = r - l;
        int m = (l + r) / 2;
        for (int i=0; i<(len/2); i++) {
            int temp = nums[l + i];
            nums[l + i] = nums[r - i - 1];
            nums[r - i - 1] = temp;
        }
    }

    public static void main(String[] args) {
        s189 s189 = new s189();
        int[] nums = new int[]{1, 2, 3, 4, 5, 6, 7};
        s189.rotate(nums, 2);
        System.out.println(Arrays.toString(nums));
    }
}
